package com.zwj.design.test.behavior.strategy.observer;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Observable;

/**
 * 被观察者
 *
 * @author 张文接
 * @version 1.0
 * @createTime 2024/3/18 23:41
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Product extends Observable {
    /**
     * 唯一标识id
     */
    private Long id;
    /**
     * 价格
     */
    private Long price;


    /**
     * 模拟价格发生了变化
     *
     * @param id    唯一标识id
     * @param price 涨幅
     */
    public void change(Long id, Long price) {
        this.id = id;
        this.price = this.price + price;
        //通知观察者
        super.setChanged();
        super.notifyObservers();
    }
}
